﻿using System;
using System.Collections.Generic;

namespace StockLib.Indicator
{
    public partial class StockKIndicator : StockIndicator
    {
        public Stock stock { get; set; }
        public StockIndicator otherIndicator { get; set; }
        public Dictionary<Stock, List<KData>> otherStockKData { get; set; }
        public bool showIndicator { get; set; }
        public int indexMin { get; protected set; }
        public int indexMax { get; protected set; }
        public KLineType klineType { get; set; }

        public StockKIndicator()
            : base()
        {
            showIndicator = true;
            klineType = KLineType.HollowLine;
        }

        public override void CalcMinMax()
        {
            if (kData == null || kData.Count <= 0)
                return;

            valueMin = Int32.MaxValue;
            valueMax = Int32.MinValue;
            indexMax = indexStart;
            indexMin = indexStart;
            for (int i = indexStart; i <= indexEnd; i++)
            {
                if (kData[i].High > valueMax)
                {
                    valueMax = kData[i].High;
                    indexMax = i;
                }

                if (kData[i].Low < valueMin)
                {
                    valueMin = kData[i].Low;
                    indexMin = i;
                }
            }

            if (showIndicator &&  otherIndicator != null)
            {
                otherIndicator.CalcMinMax();
                if (otherIndicator.valueMin < valueMin)
                    valueMin = otherIndicator.valueMin;
                if (otherIndicator.valueMax > valueMax)
                    valueMax = otherIndicator.valueMax;
            }
        }

        public override void Clear()
        {
            if (otherIndicator != null)
            {
                otherIndicator.Clear();
            }

            base.Clear();
        }

        public override List<KData> kData
        {
            get
            {
                return base.kData;
            }
            set
            {
                base.kData = value;
                if (otherIndicator != null)
                {
                    otherIndicator.kData = value;
                }
            }
        }

        public override int indexStart
        {
            get
            {
                return base.indexStart;
            }
            set
            {
                base.indexStart = value;
                if (otherIndicator != null)
                {
                    otherIndicator.indexStart = value;
                }
            }
        }

        public override int indexEnd
        {
            get
            {
                return base.indexEnd;
            }
            set
            {
                base.indexEnd = value;
                if (otherIndicator != null)
                {
                    otherIndicator.indexEnd = value;
                }
            }
        }

        public override float pointWidth
        {
            get
            {
                return base.pointWidth;
            }
            set
            {
                base.pointWidth = value;
                if (otherIndicator != null)
                {
                    otherIndicator.pointWidth = value;
                }
            }
        }
    }
}
